var express = require('express')
var bodyParser = require('body-parser')
var fs = require('fs')
var app = express()

app.use('/public', express.static('public'))
app.get('/', function (req, res) {
    res.end('111')
})
app.engine('html', require('express-art-template'));
// app.set('views', 'art');
app.get('/render', function (req, res) {
    // express默认会去views目录找index.html
    res.render('index.html', {
        title: 'hello world'
    });
})
app.get('/post', function (req, res) {
    fs.readFile('./post.html', function (err, data) {
        if (err) {
            return res.end('404 Not Found')
        } else {
            res.end(data)
        }
    })
})
var bodyencode = app.use(bodyParser.urlencoded({
    extended: false
}))
// app.use(bodyParser.urlencoded({
//     extended: false
// }))

// // parse application/json
// app.use(bodyParser.json())
app.post('/pinglun', function (req, res) {

    res.end(JSON.stringify(req.body))
})

const server = app.listen(3000, 'localhost', function () {
    const host = server.address().address
    const port = server.address().port
    console.log("应用实例，访问地址为 http://%s:%s", host, port)
})